package movement

import (
	b "code.google.com/p/gochess/board"
	pos "code.google.com/p/gochess/position"
)

// a test
var access [pos.BiggestPieceType + 1]int64

// a test
func accessible(attacker, defender b.Square, piece pos.PieceType) bool {

	//sign := int32(attacker-defender) >> 31
	value := (int32(attacker-defender) ^ int32(attacker-defender)>>31) - int32(attacker-defender)>>31
	// return ((access[piece] >> uint((value)&0x7+(value)>>4)) & 0x01) == 1
	return access[piece]>>uint(value)&0x01 == 1
}

// a test
func accessible1(attacker, defender b.Square, piece pos.PieceType) bool {
	switch piece {
	case pos.Rook:
		if (defender-attacker)&^0xF == 0 {
			return true
		}
		if (defender-attacker)&0xF == 0 {
			return true
		}
	}
	return false
	// return ((access[piece] >> uint((defender-attacker)&0xF+(defender-attacker)>>4)) & 0x01) == 1
}
